<template>
	<el-main class="bg edit_wrap comtable_e">
		<el-form ref="form" :model="form" status-icon label-width="120px" v-if="is_view()">
		<el-row class="row_ce"> 
							<el-col v-if="user_group === '管理员' || $check_field('get','list_title') || $check_field('add','list_title') || $check_field('set','list_title')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="名单标题" prop="list_title">
												<el-input id="list_title" v-model="form['list_title']" placeholder="请输入名单标题"
							  v-if="user_group === '管理员' || (form['list_of_dishonesty_id'] && $check_field('set','list_title')) || (!form['list_of_dishonesty_id'] && $check_field('add','list_title'))" :disabled="disabledObj['list_title_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','list_title')">{{form['list_title']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="user_group === '管理员' || $check_field('get','publish_tags') || $check_field('add','publish_tags') || $check_field('set','publish_tags')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="发布标签" prop="publish_tags">
												<el-input id="publish_tags" v-model="form['publish_tags']" placeholder="请输入发布标签"
							  v-if="user_group === '管理员' || (form['list_of_dishonesty_id'] && $check_field('set','publish_tags')) || (!form['list_of_dishonesty_id'] && $check_field('add','publish_tags'))" :disabled="disabledObj['publish_tags_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','publish_tags')">{{form['publish_tags']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="user_group === '管理员' || $check_field('get','release_date') || $check_field('add','release_date') || $check_field('set','release_date')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="发布日期" prop="release_date">
								<el-date-picker :disabled="disabledObj['release_date_isDisabled']" v-if="user_group === '管理员' || (form['list_of_dishonesty_id'] && $check_field('set','release_date')) || (!form['list_of_dishonesty_id'] && $check_field('add','release_date'))" id="release_date"
						v-model="form['release_date']" type="date" placeholder="选择日期">
					</el-date-picker>
					<div v-else-if="$check_field('get','release_date')">{{form['release_date']}}</div>
							</el-form-item>
			</el-col>
								<el-col v-if="user_group === '管理员' || $check_field('get','cover_photo') || $check_field('add','cover_photo') || $check_field('set','cover_photo')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="封面图片" prop="cover_photo">
								<el-upload :disabled="disabledObj['cover_photo_isDisabled']" id="cover_photo" class="avatar-uploader" drag
						accept="image/gif, image/jpeg, image/png, image/jpg" action="" :http-request="upload_cover_photo"
						:show-file-list="false" v-if="user_group === '管理员' || (form['list_of_dishonesty_id'] && $check_field('set','cover_photo')) || (!form['list_of_dishonesty_id'] && $check_field('add','cover_photo'))">
						<img v-if="form['cover_photo']" :src="$fullUrl(form['cover_photo'])" class="avatar">
						<i v-else class="el-icon-plus avatar-uploader-icon"></i>
					</el-upload>
					<el-image v-else-if="$check_field('get','cover_photo')" style="width: 100px; height: 100px"
						:src="$fullUrl(form['cover_photo'])" :preview-src-list="[$fullUrl(form['cover_photo'])]">
						<div slot="error" class="image-slot">
							<img src="../../../public/img/error.png" style="width: 90px; height: 90px" />
						</div>
					</el-image>
							</el-form-item>
			</el-col>
								<el-col v-if="user_group === '管理员' || $check_field('get','list_content') || $check_field('add','list_content') || $check_field('set','list_content')" :xs="24" :sm="24" :lg="24" class="el_form_editor_warp">
				<el-form-item label="名单内容" prop="list_content">
					<quill-editor v-model.number="form['list_content']"
						v-if="user_group === '管理员' || (form['list_of_dishonesty_id'] && $check_field('set','list_content')) || (!form['list_of_dishonesty_id'] && $check_field('add','list_content')) ">
					</quill-editor>
					<div v-else-if="$check_field('get','list_content')" v-html="form['list_content']"></div>
				</el-form-item>
			</el-col>
					
	
	
	
	
	
	
		</el-row>
			<el-col :xs="24" :sm="12" :lg="8" class="el_form_btn_warp">
				<el-form-item v-if="$check_action('/list_of_dishonesty/view','set') || $check_action('/list_of_dishonesty/view','add') || $check_option('/list_of_dishonesty/table','examine')">
					<el-button type="primary" @click="submit()">提交</el-button>
					<el-button @click="cancel()">取消</el-button>
				</el-form-item>
				<el-form-item v-else>
					<el-button @click="cancel()">返回</el-button>
				</el-form-item>
			</el-col>

		</el-form>
	</el-main>
</template>

<script>
	import mixin from "@/mixins/page.js";

	export default {
		mixins: [mixin],
		data() {
			return {
				field: "list_of_dishonesty_id",
				url_add: "~/api/list_of_dishonesty/add?",
				url_set: "~/api/list_of_dishonesty/set?",
				url_get_obj: "~/api/list_of_dishonesty/get_obj?",
				url_upload: "~/api/list_of_dishonesty/upload?",

				query: {
					"list_of_dishonesty_id": 0,
				},

				form: {
								"list_title":  '', // 名单标题
										"publish_tags":  '', // 发布标签
										"release_date":  '', // 发布日期
										"cover_photo":  '', // 封面图片
										"list_content":  '', // 名单内容
											"list_of_dishonesty_id": 0, // ID
						
				},
				disabledObj:{
								"list_title_isDisabled": false,
										"publish_tags_isDisabled": false,
										"release_date_isDisabled": false,
										"cover_photo_isDisabled": false,
										"list_content_isDisabled": false,
										},

	
		
		
		
		
	
			}
		},
		methods: {


	
	
			
	
			
	
						/**
			 * 上传封面图片
			 * @param {Object} param 图片参数
			 */
			upload_cover_photo(param){
						this.uploadFile(param.file, "cover_photo");
					},
	
	
			
	
		
			/**
			 * 获取对象之前
			 * @param {Object} param
			 */
			get_obj_before(param) {
				var form = "";
																	
				if(this.form && form){
					Object.keys(this.form).forEach(key => {
						Object.keys(form).forEach(dbKey => {
							// if(dbKey === "charging_standard"){
							// 	this.form['charging_rules'] = form[dbKey];
							// 	this.disabledObj['charging_rules_isDisabled'] = true;
							// };
							if(key === dbKey){
								this.disabledObj[key+'_isDisabled'] = true;
							}
						})
					})
				}
						        if (this.form["release_date"] && this.form["release_date"].indexOf("-")===-1){
          this.form["release_date"] = this.$toTime(parseInt(this.form["release_date"]),"yyyy-MM-dd")
        }
									$.db.del("form");

				return param;
			},

			/**
			 * 获取对象之后
			 * @param {Object} json
			 * @param {Object} func
			 */
			get_obj_after(json, func){
														if(this.form["release_date"]=="0000-00-00"){
				  this.form["release_date"] = null;
				}
				if(parseInt(this.form["release_date"]) > 9999){
					this.form["release_date"] = this.$toTime(parseInt(this.form["release_date"]),"yyyy-MM-dd")
				}
											

			},

			/**
			 * 提交前验证事件
			 * @param {Object} 请求参数
			 * @return {String} 验证成功返回null, 失败返回错误提示
			 */
			submit_check(param) {
																										if (!param.release_date){
					return "发布日期不能为空";
				}
																															return null;
			},

			is_view(){
				var bl = this.user_group == "管理员";

				if(!bl){
					bl = this.$check_action('/list_of_dishonesty/table','add');
					console.log(bl ? "你有表格添加权限视作有添加权限" : "你没有表格添加权限");
				}
				if(!bl){
					bl = this.$check_action('/list_of_dishonesty/table','set');
					console.log(bl ? "你有表格添加权限视作有修改权限" : "你没有表格修改权限");
				}
				if(!bl){
					bl = this.$check_action('/list_of_dishonesty/view','add');
					console.log(bl ? "你有视图添加权限视作有添加权限" : "你没有视图添加权限");
				}
				if(!bl){
					bl = this.$check_action('/list_of_dishonesty/view','set');
					console.log(bl ? "你有视图修改权限视作有修改权限" : "你没有视图修改权限");
				}
				if(!bl){
					bl = this.$check_action('/list_of_dishonesty/view','get');
					console.log(bl ? "你有视图查询权限视作有查询权限" : "你没有视图查询权限");
				}

				console.log(bl ? "具有当前页面的查看权，请注意这不代表你有字段的查看权" : "无权查看当前页，请注意即便有字段查询权限没有页面查询权限也不行");

				return bl;
			},
			/**
			 * 上传文件
			 * @param {Object} param
			 */
			uploadimg(param) {
				this.uploadFile(param.file, "avatar");
			},

		},
		created() {
												},
	}
</script>

<style>
	.avatar-uploader .el-upload {
		border: 1px dashed #d9d9d9;
		border-radius: 6px;
		cursor: pointer;
		position: relative;
		overflow: hidden;
	}

	.avatar-uploader .el-upload:hover {
		border-color: #409EFF;
	}

	.avatar-uploader-icon {
		font-size: 28px;
		color: #8c939d;
		width: 178px;
		height: 178px;
		line-height: 178px;
		text-align: center;
	}

	.avatar {
		width: 178px;
		height: 178px;
		display: block;
	}




</style>
